package com.example.broadcasttutital.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.broadcasttutital.R;
import com.example.broadcasttutital.orderedbroadcast.Test0Receiver;
import com.example.broadcasttutital.orderedbroadcast.Test1Receiver;
import com.example.broadcasttutital.orderedbroadcast.Test2Receiver;
import com.example.broadcasttutital.orderedbroadcast.Test3Receiver;

public class OrderedBroadcastActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_local_broadcastreceiver);

        IntentFilter filter2 = new IntentFilter();
        filter2.addAction("com.example.broadcast.MY_ORDERED_BROADCAST");
        filter2.setPriority(999);
        this.registerReceiver(new Test2Receiver(),filter2);

        IntentFilter filter1 = new IntentFilter();
        filter1.addAction("com.example.broadcast.MY_ORDERED_BROADCAST");
        filter1.setPriority(1000);
        this.registerReceiver(new Test1Receiver(), filter1);

        IntentFilter filter3 = new IntentFilter();
        filter3.addAction("com.example.broadcast.MY_ORDERED_BROADCAST");
        filter3.setPriority(998);
        this.registerReceiver(new Test3Receiver(), filter3);

        Button button2 = findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("com.example.broadcast.MY_ORDERED_BROADCAST");
                sendOrderedBroadcast(intent,null,new Test0Receiver(), null, Activity.RESULT_OK,"国家发放补贴1000",null);
            }
        });

    }
}
